package us.wili.dev.third.util.example.cases;

import cn.jpush.api.JPushClient;
import cn.jpush.api.common.resp.APIConnectionException;
import cn.jpush.api.common.resp.APIRequestException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

/**
 * 极光推送示例
 * 示例只阐述了工具的部分方法，更多方法的使用，请对比文档，文档地址：https://docs.jiguang.cn/jpush/server/push/server_overview/
 * <p>
 * author: lefore
 * date: 2018/9/30
 */
public class JiGuangCase {

    private static final Logger logger = LoggerFactory.getLogger(JiGuangCase.class);

    @Autowired
    private JPushClient jPushClient;

    /**
     * 推送通知到安卓端
     */
    public void sendAndroidNotification() {
        String title = "标题";
        String alert = "内容";
        String alias = "wili";
        Map<String, String> extraMap = new HashMap<>(1);
        extraMap.put("extra", "extraMsg");

        try {
            jPushClient.sendAndroidNotificationWithAlias(title, alert, extraMap, alias);
        } catch (APIConnectionException | APIRequestException e) {
            logger.error("推送失败", e);
        }
    }

    /**
     * 推送通知到 IOS 端
     */
    public void sendIOSNotfication() {
        String alert = "内容";
        String alias = "wili";
        Map<String, String> extraMap = new HashMap<>(1);
        extraMap.put("extra", "extraMsg");

        try {
            jPushClient.sendIosNotificationWithAlias(alert, extraMap, alias);
        } catch (APIConnectionException | APIRequestException e) {
            logger.error("推送失败", e);
        }
    }
}